/*Segment errors: invalid dereference - exploits.*/
#include <stdio.h>
#include <string.h>

/* On a secure system, this code should never be allowed to execute.
   Unfortunately, on an embedded system that shares code and data memory,
   it can be exploited to execute malious code on the stack. */

void print_nchars(char *s, int n)
{
  for(int i = 0; i < n; i++)
    printf("%c", s[i]);
}

void print_secret()
{
  printf("secret info\n");
}

int main()
{
  int a[1000];
  memcpy(a, print_secret, 1000); /* or input malious code */

  int (*fp)() = (int (*)())a;
  (*fp)();

  return 0;
}
